import {defineStore} from 'pinia'
import type {UserState} from '../interface'
import piniaPersistConfig from '@/config/piniaPersist'
export const useUserStore = defineStore(
  'UserStore',
  () => {
    const state = reactive({
      token: '',
      userInfo: {name: 'Akiko'}
    })

    const getters = computed(() => 'test')
    const setToken = (tk: string) => {
      state.token = tk
    }
    const setUserInfo = (info: UserState['userInfo']) => {
      state.userInfo = info
    }

    return {
      ...toRefs(state),
      getters,
      setToken,
      setUserInfo
    }
  },
  {
    persist: piniaPersistConfig('UserState')
  }
)

// export const useUserStore = defineStore('UserStore', {
//     state: (): UserState => ({
//         token: "",
//         userInfo: { name: "Akiko" }
//     }),
//     getters: {},
//     actions: {
//         /**
//          * 设置 token 值
//          *
//          * @param token token 字符串
//          */
//         setToken(token: string) {
//             this.token = token
//         },
//         /**
//          * 设置用户信息
//          *
//          * @param userInfo 用户信息对象，类型为UserState["userInfo"]
//          */
//         setUserInfo(userInfo: UserState["userInfo"]) {
//             this.userInfo = userInfo
//         }
//     },
//     persist: piniaPersistConfig("UserState")
// })
